// @coding: utf8

#include <iostream>
#include <vector>
#include <random>
#include <ctime>

void init_test_data(std::vector<int>& data1, std::vector<int>& data2)
{
    srand(time(nullptr));
    int len1 = rand() % 10;
    int len2 = rand() % 10;
    for (auto idx = 0; idx < len1; ++idx)
    {
        data1.push_back(rand() % 10);
    }
    std::sort(data1.begin(), data1.end());
    for (auto idx = 0; idx < len2; ++idx)
    {
        data2.push_back(rand() % 10);
    }
    std::sort(data2.begin(), data2.end());
}

std::vector<int> merge_with_order(std::vector<int>& data1, std::vector<int>& data2)
{
    std::vector<int> result;
    std::size_t idx1 = 0;
    std::size_t idx2 = 0;
    while (idx1 < data1.size() && idx2 < data2.size())
    {
        if (data1[idx1] < data2[idx2])
            result.push_back(data1[idx1++]);
        else
            result.push_back(data2[idx2++]);
    }
    while (idx1 < data1.size())
    {
        result.push_back(data1[idx1++]);
    }
    while (idx2 < data2.size())
    {
        result.push_back(data2[idx2++]);
    }
    return result;
}

void dump_vector(std::vector<int>& vec)
{
    std::cout << "dump_vector:" << std::endl;
    for (auto val : vec)
    {
        std::cout << val << ",";
    }
    std::cout << std::endl;
}

int main()
{
    std::vector<int> left_data;
    std::vector<int> right_data;
    init_test_data(left_data, right_data);
    dump_vector(left_data);
    dump_vector(right_data);
    auto result_data = merge_with_order(left_data, right_data);
    dump_vector(result_data);
    return 0;
}